package com.theydream.qeechain.map;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

/**
 * Self Defined Map Overlays
 *
 */
public class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay {

	// ================================================================
	// Fields
	// ================================================================

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	// ================================================================
	// Contructors
	// ================================================================

	public ItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		populate();
		// TODO Auto-generated constructor stub
	}

	public ItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		populate();
		mContext = context;
	}

	// ================================================================
	// Inheried methods
	// ================================================================

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		
//		OverlayItem item = mOverlays.get(index);
//		double radius=1000.0;
//		GlobalData gbData=GlobalData.getInstance();
//		Location markerLocation=new Location("Maker");
//		markerLocation.setLatitude(item.getPoint().getLatitudeE6()/1E6);
//		markerLocation.setLongitude(item.getPoint().getLongitudeE6()/1E6);
//		
//		if (true)
//		
//		//if (markerLocation.distanceTo(gbData.getUserLocation()) <radius)
//		{
//			AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//			dialog.setTitle("Change Location");
//			dialog.setMessage("GOGOGO"+GlobalData.getInstance().getUserLocation().getLatitude()+" "+GlobalData.getInstance().getUserLocation().getLongitude());
//			//dialog.setMessage("GOGOGO"+markerLocation.distanceTo(gbData.getUserLocation()) );
//					dialog.show();
//		}
//		else
//		{
//		
//		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//		dialog.setTitle(item.getTitle());
//		dialog.setMessage(item.getSnippet()+markerLocation.distanceTo(gbData.getUserLocation()) );
//				dialog.show();
//		}
		
		
//		OverlayItem item = mOverlays.get(index);
//		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//		dialog.setTitle(item.getTitle());
//		dialog.setMessage(item.getSnippet());
//		dialog.show();
		return true;
	}

	/* (non-Javadoc)
	 * @see com.google.android.maps.ItemizedOverlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
	 * Draw item without shadow
	 */
	@Override
	public void draw(android.graphics.Canvas canvas,MapView mapView,boolean shadow) {

		if (!shadow)
			super.draw(canvas, mapView, false);

			}
}
